Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigationHeight: 64,
    navigationTop: 26,
    navigationLeft: 10,
    capsuleWidth: 87,
    provinceName: '',
    badgeImageUrl: '',
    allShopList: []
  },
  goback() {
    wx.navigateBack({
      fail() {
        wx.redirectTo({
          url: '/pages/index/index',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const navigationBtnObj = wx.getMenuButtonBoundingClientRect()
    wx.getSystemInfo({
      success: res => {
        this.setData({
          navigationHeight: res.statusBarHeight + navigationBtnObj.height + (navigationBtnObj.top - res.statusBarHeight) * 2,
          navigationTop: navigationBtnObj.top,
          navigationLeft: res.windowWidth - navigationBtnObj.right,
          capsuleWidth: navigationBtnObj.width
        })
      }
    })

    let provinceData = wx.getStorageSync('medalProvinceData').filter(item => item.provinceId == options.provinceId)[0]
    let allShopList = provinceData.shopList
    let userMedalData = wx.getStorageSync('userMedalData').filter(item => item.provinceId == options.provinceId)[0]
    let lightShopList = (userMedalData && userMedalData.shopList) || []
    if (lightShopList.length) {
      allShopList.forEach(item => {
        lightShopList.forEach(light => {
          if(item.shopId == light.shopId){
            item.active = true
            item.createTime = light.createTime.split(' ')[0].replace(/-/g, '.')
            item.scanCount = light.scanCount
          }
        })
      })
      allShopList = allShopList.sort((a, b) => (b.active || 0) - (a.active || 0))
    }
    this.setData({
      allShopList: allShopList,
      provinceName: provinceData.provinceName,
      badgeImageUrl: wx.getStorageSync('badgeImageUrl')
    })

  }
})